package model

import (
	"pet-server/basic/config"
	"time"
)

// 套餐表
type Combo struct {
	Id        uint64    `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	CreatedAt time.Time `gorm:"column:created_at;type:datetime(3);default:NULL;" json:"created_at"`
	UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3);default:NULL;" json:"updated_at"`
	DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
	Pet       string    `gorm:"column:pet;type:varchar(30);comment:宠物;default:NULL;" json:"pet"`           // 宠物
	Address   string    `gorm:"column:address;type:varchar(50);comment:地址;default:NULL;" json:"address"`   // 地址
	Store     string    `gorm:"column:store;type:varchar(20);comment:门店;default:NULL;" json:"store"`       // 门店
	Service   string    `gorm:"column:service;type:varchar(50);comment:服务介绍;default:NULL;" json:"service"` // 服务介绍
}

func (c *Combo) TableName() string {
	return "combo"
}

// 套餐列表
func (c *Combo) ListCombo(page, pageSize int) ([]Combo, int64, error) {
	if page <= 0 {
		page = 1
	}
	if pageSize <= 0 || pageSize >= 100 {
		pageSize = 10
	}
	var total int64
	var com []Combo
	config.DB.Model(&Combo{}).Where("deleted_at IS NULL").Count(&total)
	err := config.DB.Where("deleted_at IS NULL").Offset((page - 1) * pageSize).Limit(pageSize).Find(com).Error
	return com, total, err

}

// 套餐详情页
func (c *Combo) FirstCombo() error {
	return config.DB.Where("id =?", c.Id).First(c).Error
}
